package com.tea.funct.controller;

import com.tea.common.annotation.Log;
import com.tea.common.core.controller.BaseController;
import com.tea.common.core.domain.AjaxResult;
import com.tea.common.core.page.TableDataInfo;
import com.tea.common.enums.BusinessType;
import com.tea.common.utils.poi.ExcelUtil;
import com.tea.funct.domain.TeaInform;
import com.tea.funct.service.ITeaInformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 通知管理Controller
 *
 * @author Sophia
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/funct/inform")
public class TeaInformController extends BaseController {
    @Autowired
    private ITeaInformService teaInformService;

    /**
     * 查询通知管理列表
     */
    @PreAuthorize("@ss.hasPermi('funct:inform:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaInform teaInform) {
        startPage();
        List<TeaInform> list = teaInformService.selectTeaInformList(teaInform);
        return getDataTable(list);
    }

    /**
     * 导出通知管理列表
     */
    @PreAuthorize("@ss.hasPermi('funct:inform:export')")
    @Log(title = "通知管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaInform teaInform) {
        List<TeaInform> list = teaInformService.selectTeaInformList(teaInform);
        ExcelUtil<TeaInform> util = new ExcelUtil<TeaInform>(TeaInform.class);
        util.exportExcel(response, list, "通知管理数据");
    }

    /**
     * 获取通知管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('funct:inform:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(teaInformService.selectTeaInformById(id));
    }

    /**
     * 新增通知管理
     */
    @PreAuthorize("@ss.hasPermi('funct:inform:add')")
    @Log(title = "通知管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaInform teaInform) {
        return toAjax(teaInformService.insertTeaInform(teaInform));
    }

    /**
     * 修改通知管理
     */
    @PreAuthorize("@ss.hasPermi('funct:inform:edit')")
    @Log(title = "通知管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaInform teaInform) {
        return toAjax(teaInformService.updateTeaInform(teaInform));
    }

    /**
     * 删除通知管理
     */
    @PreAuthorize("@ss.hasPermi('funct:inform:remove')")
    @Log(title = "通知管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(teaInformService.deleteTeaInformByIds(ids));
    }
}
